﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using WalkingTec.Mvvm.Core;
using System.Text.Json.Serialization;
using nERP.Model;
using nERP.Model.Bas;
using nERP.Model.Po;
using nERP.Model.So;
using nERP.Model.Wms;

namespace nERP.Model.Bas
{
    /// <summary>
    /// 商品管理
    /// </summary>
	[Table("Goods")]
    [SoftKey(nameof(Goods.GoodsCode))]
    [Display(Name = "_Model.Goods")]
    public class Goods : BasePoco, IPersistPoco, ITenant
    {
        [Display(Name = "_Model._Goods._GoodsCode")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("商品编号")]
        [Required(ErrorMessage = "Validate.{0}required")]
        [CanNotEdit]
        public string GoodsCode { get; set; }
        [Display(Name = "_Model._Goods._GoodsName")]
        [StringLength(64, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("商品名称")]
        [Required(ErrorMessage = "Validate.{0}required")]
        public string GoodsName { get; set; }
        [Display(Name = "_Model._Goods._GoodsType")]
        [Comment("商品类别")]
        [NotMapped]
        public GoodsClass GoodsType { get; set; }
        [Display(Name = "_Model._Goods._GoodsType")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("商品类别")]
        [Required(ErrorMessage = "Validate.{0}required")]
        public string GoodsTypeId { get; set; }
        [Display(Name = "_Model._Goods._GoodsSpec")]
        [StringLength(64, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("规格型号")]
        public string GoodsSpec { get; set; }
        [Display(Name = "_Model._Goods._GoodsUnit")]
        [Comment("计量单位")]
        [NotMapped]
        public ComputationUnit GoodsUnit { get; set; }
        [Display(Name = "_Model._Goods._GoodsUnit")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("计量单位")]
        public string GoodsUnitId { get; set; }
        [Display(Name = "_Model._Goods._RestockingPrice")]
        [Comment("进货价")]
        public decimal? RestockingPrice { get; set; }
        [Display(Name = "_Model._Goods._RetailPrice")]
        [Comment("零售价")]
        public decimal? RetailPrice { get; set; }
        [Display(Name = "_Model._Goods._WholesalePrice")]
        [Comment("批发价")]
        public decimal? WholesalePrice { get; set; }
        [Display(Name = "_Model._Goods._SafetyStock")]
        [Comment("安全库存")]
        public decimal? SafetyStock { get; set; }
        [Display(Name = "_Model._Goods._Remark")]
        [StringLength(256, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("备注")]
        public string Remark { get; set; }
        [Display(Name = "_Model._Goods._GoodsImages")]
        [Comment("商品图片")]
        public List<GoodsGoodsImages> GoodsImages { get; set; }
        [Display(Name = "_Model._Goods._Stock")]
        [Comment("库存")]
        [NotMapped]
        public decimal? Stock { get; set; }
        [Display(Name = "_Model._BuyDetail._Goods")]
        [InverseProperty("Goods")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Po.BuyDetail.GoodsId))]
        public List<BuyDetail> BuyDetail_Goods { get; set; }
        [Display(Name = "_Model._BuyReturnDetail._Goods")]
        [InverseProperty("Goods")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Po.BuyReturnDetail.GoodsId))]
        public List<BuyReturnDetail> BuyReturnDetail_Goods { get; set; }
        [Display(Name = "_Model._SaleDetail._Goods")]
        [InverseProperty("Goods")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.So.SaleDetail.GoodsId))]
        public List<SaleDetail> SaleDetail_Goods { get; set; }
        [Display(Name = "_Model._SaleReturnDetail._Goods")]
        [InverseProperty("Goods")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.So.SaleReturnDetail.GoodsId))]
        public List<SaleReturnDetail> SaleReturnDetail_Goods { get; set; }
        [Display(Name = "_Model._BuyInWarehouseDetail._Goods")]
        [InverseProperty("Goods")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Wms.BuyInWarehouseDetail.GoodsId))]
        public List<BuyInWarehouseDetail> BuyInWarehouseDetail_Goods { get; set; }
        [Display(Name = "_Model._BuyReturnOutWarehouseDetail._Goods")]
        [InverseProperty("Goods")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Wms.BuyReturnOutWarehouseDetail.GoodsId))]
        public List<BuyReturnOutWarehouseDetail> BuyReturnOutWarehouseDetail_Goods { get; set; }
        [Display(Name = "_Model._SaleOutWarehouseDetail._Goods")]
        [InverseProperty("Goods")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Wms.SaleOutWarehouseDetail.GoodsId))]
        public List<SaleOutWarehouseDetail> SaleOutWarehouseDetail_Goods { get; set; }
        [Display(Name = "_Model._SaleReturnInWarehouseDetail._Goods")]
        [InverseProperty("Goods")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Wms.SaleReturnInWarehouseDetail.GoodsId))]
        public List<SaleReturnInWarehouseDetail> SaleReturnInWarehouseDetail_Goods { get; set; }
        [Display(Name = "_Model._OtherInWarehouseDetail._Goods")]
        [InverseProperty("Goods")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Wms.OtherInWarehouseDetail.GoodsId))]
        public List<OtherInWarehouseDetail> OtherInWarehouseDetail_Goods { get; set; }
        [Display(Name = "_Model._OtherOutWarehouseDetail._Goods")]
        [InverseProperty("Goods")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Wms.OtherOutWarehouseDetail.GoodsId))]
        public List<OtherOutWarehouseDetail> OtherOutWarehouseDetail_Goods { get; set; }
        [Display(Name = "_Model._Goods._IsValid")]
        [Comment("是否有效")]
        [Required(ErrorMessage = "Validate.{0}required")]
        public bool IsValid { get; set; } = true;
        [StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
        public string TenantCode { get; set; }

    }
    public class GoodsGoodsImages : TopBasePoco, ISubFile
    {
        public Guid GoodsId { get; set; }
        public Goods Goods { get; set; }
        public Guid FileId { get; set; }
        public FileAttachment File { get; set; }
        public int Order { get; set; }
    }

}
